package com.lst.api.vo;

import com.lst.api.entity.WorkCompanyInfo;
import com.lst.api.exception.RequestParamErrorException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * 工作单位信息
 *
 * @author Frank
 * @date 2019-12-30 10:31:38
 * @version: V1.0
 */
@Data
@NoArgsConstructor
public class WorkCompanyInfoVo implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "companyName", value = "单位名称", required = true, dataType = "String")
    private String companyName;

    @ApiModelProperty(name = "department", value = "任职部门", required = true, dataType = "String")
    private String department;

    @ApiModelProperty(name = "post", value = "职务", required = true, dataType = "String")
    private String post;

    @ApiModelProperty(name = "addressProvinceCode", value = "单位地址，省编号", required = true, dataType = "String")
    private String  addressProvinceCode;

    @ApiModelProperty(name = "addressCityCode", value = "单位地址，市编号", required = true, dataType = "String")
    private String  addressCityCode;

    @ApiModelProperty(name = "addressAreaCode", value = "单位地址，区编号", required = true, dataType = "String")
    private String  addressAreaCode;

    @ApiModelProperty(name = "addressDetails", value = "单位地址，详细地址", required = true, dataType = "String")
    private String  addressDetails;

    @ApiModelProperty(name = "companyPhone", value = "单位电话", required = true, dataType = "String")
    private String companyPhone;

    @ApiModelProperty(name = "industryTypeId", value = "单位类型", required = true, dataType = "Long")
    private Long industryTypeId;

    public WorkCompanyInfoVo(WorkCompanyInfo workCompanyInfo) {
        if (workCompanyInfo == null) {
            return;
        }
        this.companyName = workCompanyInfo.getCompanyName();
        this.department = workCompanyInfo.getDepartment();
        this.post = workCompanyInfo.getPost();
        this.addressProvinceCode = workCompanyInfo.getAddressProvinceCode();
        this.addressCityCode = workCompanyInfo.getAddressCityCode();
        this.addressAreaCode = workCompanyInfo.getAddressAreaCode();
        this.addressDetails = workCompanyInfo.getAddressDetails();
        this.companyPhone = workCompanyInfo.getCompanyPhone();
        this.industryTypeId = workCompanyInfo.getIndustryTypeId();
    }

    public void check() {
        boolean check = StringUtils.isNotBlank(this.companyName)
                && StringUtils.isNotBlank(this.department)
                && StringUtils.isNotBlank(this.post)
                && StringUtils.isNotBlank(this.addressProvinceCode)
                && StringUtils.isNotBlank(this.addressCityCode)
                && StringUtils.isNotBlank(this.addressAreaCode)
                && StringUtils.isNotBlank(this.addressDetails)
                && StringUtils.isNotBlank(this.companyPhone)
                && this.industryTypeId != null;
        if (!check) {
            throw new RequestParamErrorException("WorkCompanyInfoVo请求参数不合法！");
        }
    }

    public boolean isAllFieldNull() {
        return StringUtils.isBlank(this.companyName)
                && StringUtils.isBlank(this.department)
                && StringUtils.isBlank(this.post)
                && StringUtils.isBlank(this.addressProvinceCode)
                && StringUtils.isBlank(this.addressCityCode)
                && StringUtils.isBlank(this.addressAreaCode)
                && StringUtils.isBlank(this.addressDetails)
                && StringUtils.isBlank(this.companyPhone)
                && this.industryTypeId == null;
    }
}